<template>
  <div class="box">
    <p class="p_title">
      <el-button type="text" style="color: #000;font-size: 16px">管理员信息</el-button>
    </p>
    <el-form :model="addUnitForm" :rules="rules" ref="addUnitForm" label-width="130px" disabled>
      <el-form-item label="身份证号" prop="sid" class="el_w">
        <el-input v-model="addUnitForm.sid"></el-input>
      </el-form-item>
      <el-form-item label="姓名" prop="displayname" class="el_w">
        <el-input v-model="addUnitForm.displayname"></el-input>
      </el-form-item>
      <el-form-item label="账号" prop="account" class="el_w">
        <el-input v-model="addUnitForm.account"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex" class="el_w">
        <el-select v-model="addUnitForm.sex" placeholder="请输入性别" style="width: 100%">
          <el-option
            v-for="item in sexBox"
            :key="item.id"
            :label="item.value"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="描述" prop="description" class="el_w">
        <el-input v-model="addUnitForm.description"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email" class="el_w">
        <el-input v-model="addUnitForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="phone" class="el_w">
        <el-input v-model="addUnitForm.phone"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="status" class="el_w">
        <el-select v-model="addUnitForm.status" placeholder="请选择状态" style="width: 100%">
          <el-option
            v-for="item in statusBox"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-footer class="el_foot">
      <el-button type="primary" @click="back">返 回</el-button>
    </el-footer>
  </div>
</template>

<script>
  import {http} from "../../../assets/commonjs/axios";
  import {$aos} from "../../../store/state";
  import {delSurplus} from "../../../assets/commonjs/utils";

  export default {
    name: "seeAdmin",
    data() {
      return {
        orgId: null,
        orgname: '',
        sexBox: [   //性别的下拉框数据
          {id: "男", value: "男"},
          {id: "女", value: "女"},
        ],
        statusBox: [///状态的下拉框数据
          {value: 0, label: "无效"},
          {value: 1, label: "有效"},
          {value: 2, label: "有效"},
        ],
        addUnitForm: {
          sid: '',//身份证号
          displayname: '',//姓名
          account: '',//账号
          sex: "",//性别
          description: "",//描述
          email: "",//邮箱,
          phone: "",//手机号
          status: "",//状态
        },
        UnitForm: {
          applyType: 4,//1：新建 2.编辑 3.删除 4 预览
          uid: '',
          urId: ''
        },
        rules: {
          sid: [
            {required: true, message: "请填写身份证号", trigger: "blur"}
          ],
          displayname: [
            {required: true, message: "请填写姓名", trigger: "blur"}
          ],
          account: [
            {required: true, message: "请填写账号", trigger: "blur"}
          ],
          sex: [
            {required: true, message: "请选择性别", trigger: "blur"}
          ],
          phone: [
            {required: true, message: "请填写手机号", trigger: "blur"}
          ],
        },
      }
    },
    created() {
      this.orgId = this.$route.query.orgs;
      $aos.getItem('loginData').then(res => {
        this.orgname = res.org.orgname;
      });
      $aos.getItem('adminData').then(res => {
        this.UnitForm.uid = res.uid;
        this.UnitForm.urId = res.urId;
        this.submitAddUnit();
      })
    },
    methods: {
      back() {
        $aos.setItem('tabNum', 1);
        this.$router.push({path: '/containerDetails', query: {index: 1, orgId: this.orgId}});
        setTimeout(_ => {
          this.$router.push({path: '/containerDetail', query: {index: 1, orgId: this.orgId}});
        },)
      },
      submitAddUnit() {
        http('post', 'permission/opera_user', {
          user: this.UnitForm
        }).then(res => {
          if (res.data.success) {
            let info = res.data.data.user
            this.addUnitForm = delSurplus(info, this.addUnitForm);
          }
        })

      }
    }
  }
</script>

<style scoped>
  .box {
    background: #fff;
    height: 100%;
  }

  .p_title {
    padding: 10px 40px 10px 20px;
    margin: 0;
  }

  .el_w {
    width: 30%;
  }

  .el_foot {
    width: 40%;
    text-align: center;
    margin: 40px auto;
  }
</style>
